<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: Automatic wrapper functions</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_autowrap.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Automatic wrapper functions </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/autowrapper/aswrappedcall.h</p>
<p>This header file declares some macros and template functions that will let the application developer automatically generate wrapper functions using the <a class="el" href="doc_generic.html">generic calling convention</a> with a simple call to a preprocessor macro. This is useful for those platforms where the native calling conventions are not yet supported.</p>
<p>The macros are defined as</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#define asDECLARE_FUNCTION_WRAPPER(wrapper_name,func)</span>
<span class="preprocessor"></span><span class="preprocessor">#define asDECLARE_FUNCTION_WRAPPERPR(wrapper_name,func,params,rettype)</span>
<span class="preprocessor"></span><span class="preprocessor">#define asDECLARE_METHOD_WRAPPER(wrapper_name,cl,func)</span>
<span class="preprocessor">#define asDECLARE_METHOD_WRAPPERPR(wrapper_name,cl,func,params,rettype)</span>
</pre></div><p>where wrapper_name is the name of the function that you want to generate, and func is a function pointer to the function you want to wrap, cl is the class name, params is the parameter list, and rettype is the return type.</p>
<p>Unfortunately the template functions needed to perform this generation are quite complex and older compilers may not be able to handle them. One such example is Microsoft Visual C++ 6, though luckily it has no need for them as AngelScript already supports native calling conventions for it.</p>
<h2><a class="anchor" id="doc_addon_autowrap_1"></a>
Example usage</h2>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;aswrappedcall.h&quot;</span>

<span class="comment">// The application function that we want to register</span>
<span class="keywordtype">void</span> DoSomething(std::string param1, <span class="keywordtype">int</span> param2);

<span class="comment">// Generate the wrapper for the function</span>
asDECLARE_FUNCTION_WRAPPER(DoSomething_Generic, DoSomething);

<span class="comment">// Registering the wrapper with AngelScript</span>
<span class="keywordtype">void</span> RegisterWrapper(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine)
{
  <span class="keywordtype">int</span> r;

  r = engine-&gt;<a class="code" href="classas_i_script_engine.html#a754fafd069d8e0c19baff2dc222893b0" title="Registers a global function.">RegisterGlobalFunction</a>(<span class="stringliteral">&quot;void DoSomething(string, int)&quot;</span>, <a class="code" href="angelscript_8h.html#a78f8f2c7f1c88b12e74a5ac47b4184ae" title="Returns an asSFuncPtr representing the function specified by the name.">asFUNCTION</a>(DoSomething_Generic), <a class="code" href="angelscript_8h.html#a3ec92ea3c4762e44c2df788ceccdd1e4a750c26b6a6e0c9ccbb93078f532ef8ce" title="A function using the generic calling convention.">asCALL_GENERIC</a>); assert( r &gt;= 0 );
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
